<template>
  <div>
    <form-view  class="ant-drawer-body" v-if="this.formType=='zdybd'" ref="formView" :formId="formId" :dataId="dataId"
               @saveCallback="saveCallback" :disabled="isDetail"></form-view>
    <component class="ant-drawer-body" v-if="this.formType=='wbbd'"  ref="formView" :is="routeFormComponent"  :dataId="dataId"
               @saveCallback="saveCallback" :disabled="isDetail"></component>
    <!--流程发起申请按钮-->
    <div class="drawer-bootom-button" style="bottom:initial">
      <div v-if="editMain" :wrapperCol="{ span: 24 }" class="mb0 tr" >
        <a-button type="primary" @click="saveApply">提交申请</a-button>
        <a-button type="primary" style="margin-left: 8px" @click="saveForm">保存草稿</a-button>
        <a-button style="margin-left: 8px"  @click="close">取消</a-button>
      </div>
      <!--流程表单详情关闭按钮-->
      <div v-if="isDetail" :wrapperCol="{ span: 24 }" class="mb0 tr">
        <a-button type="primary" style="margin-left: 8px" @click="close">关闭</a-button>
      </div>
    </div>
  </div>
</template>
<script>
  import FormView from "@/components/form/FormView";
  export default {
    name: 'FormDataEdit',
    components: {
      FormView
    },
    props:{
      /*流程数据*/
      processData:{
        type:Object,
        default:()=>{return {}},
        required:false
      },
      editMain: {type: Boolean, default: false, required: false},
      isDetail: {type: Boolean, default: false, required: false},
    },
    data () {
      return {
        formType:"",
        routeUrl:"",
        formId:"",
        dataId:"",
        disabled: false,
        btndisabled: false,
        hasNodeForm:false,
        userLoading: false,
        assigneeList: [],
        showAssign: true,
        error: "",
        routeFormComponent:"",
        commitApply: false,
      }
    },
    created() {
      console.log("流程数据",this.processData)
      this.formId=this.processData.formId;
      this.dataId=this.processData.tableId;

      this.formType=this.processData.formType;
      this.routeUrl=this.processData.routeUrl;
      if(this.formType=='wbbd'){
        var myComponent =() => import("@/views/"+this.routeUrl);
        this.routeFormComponent = myComponent;
      }
    },
    methods: {
      saveApply() {
        this.commitApply = true;
        this.saveForm();
      },
      saveForm() {
        this.btndisabled = true;
        this.$refs.formView.saveForm();
        this.btndisabled = false;
      },
      saveCallback(formData){
        formData.formType=this.formType;
        formData.formId=this.formId;
        formData.routeUrl=this.routeUrl;
        formData.commitApply = this.commitApply;
        this.$emit('afterSubmit',formData)
      },
      close() {
        //todo 关闭后的回调
        this.commitApply = false;
        this.$emit('close')
      },
    },
  }
</script>
<style lang="less" scoped>

</style>